package com.zclcs.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zclcs.model.DataRet;
import com.zclcs.model.Menu;
import com.zclcs.model.RolePermission;
import com.zclcs.service.MenuService;

/**
 * 菜单控制器 GET 用来获取资源， POST 用来新建资源（也可以用于更新资源）， PUT 用来更新资源， DELETE 用来删除资源。
 * 
 * @author 周成龙
 *
 */
@RestController
public class MenuController {

	@Autowired
	private MenuService menuService;

	@RequiresPermissions(value = "p_menu_menu")
	@GetMapping(value = "/menu/selectMenu")
	public DataRet<List<Menu>> selectMenu(Menu menu) {

		return new DataRet<List<Menu>>(menuService.selectMenu(menu));

	}

	@PostMapping(value = "/menu/insertMenu")
	public void insertMenu(Menu menu) {

		menuService.insertMenu(menu);

	}

	@PutMapping(value = "/menu/updateMenu")
	public void updateMenu(Menu menu) {

		menuService.updateMenu(menu);

	}

	@PutMapping(value = "/menu/updateChildrenMenu")
	public void updateChildrenMenu(Menu menu) {

		menuService.updateChildrenMenu(menu);

	}

	@DeleteMapping(value = "/menu/deleteMenu")
	public DataRet<Object> deleteMenu(@RequestParam(value = "ids[]") List<String> ids) {

		return menuService.deleteMenu(ids);

	}

	@PostMapping(value = "/menu/validMenuName")
	public DataRet<Object> validMenuName(Menu menu) {

		return new DataRet<Object>(menuService.validMenuName(menu));

	}

	@PostMapping(value = "/menu/validMenuPermission")
	public DataRet<Object> validMenuPermission(Menu menu) {

		return new DataRet<Object>(menuService.validMenuPermission(menu));

	}

	@PostMapping(value = "/menu/pickUpRoleMenus")
	public void pickUpRoleMenus(RolePermission rolePermission) {

		menuService.pickUpRoleMenus(rolePermission);

	}

	@DeleteMapping(value = "/menu/putDownRoleMenus")
	public void putDownRoleMenus(RolePermission rolePermission) {

		menuService.putDownRoleMenus(rolePermission);

	}

}
